
/// This file generates all tables and figures for the county-year level data


// Font type
graph set window fontface "Times New Roman"
graph set eps fontface "Times New Roman"


**Set "Style"
	grstyle clear , erase
	grstyle init
	grstyle set plain, horizontal nogrid

**Set color scheme for paper
	grstyle set color economist
	
// export file for Figure 3 - maps. Combine with Census shapefile in QGIS. 
preserve
keep fstate fcounty year RI_cvap pcvap

// generate county identifier that maps shapefile
tostring fstate fcounty, replace  
replace fcounty="0"+fcounty if length(fcounty)==2
replace fcounty="00"+fcounty if length(fcounty)==1
replace fstate="0"+fstate if length(fstate)==1
gen fips=fstate+fcounty

collapse (mean) RI_cvap pcvap , by(fstate fcounty fips)

export delim "$OutputPath/countydistrict_tomap.csv", replace
restore 


* Set covariates and standard errors
global x purban pbelowpoverty medhhinc pblack phispanic pfemale punemployed pbachelors page65_up 

global pol  pincumbent pdemreps pdemrepsxdemmajority 

global cvar stateyear

* Use the same balanced sample for all regressions
reghdfe logrev_state logRI_cvap logpop logcvap  $x $pol  , a(countyid stateyear) vce(cluster $cvar)
gen fesample_v=(e(sample)==1)

reghdfe logrev_state logRI_cvap logpop logcvap  $x $pol  , a(stateyear) vce(cluster $cvar)
replace fesample_v=0 if e(sample)!=1

keep if fesample_v==1

egen balanced = total(inrange(year, 2002, 2017)), by(countyid)
replace fesample_v=0 if balanced!=3

keep if fesample_v==1


* label variables used in Tables and Figures
label variable rev_statepc 				"Per capita transfers from state to county"
label variable pcvap 					"\% CVAP"
label variable purban 					"\% urban"
label variable pblacknh					"\% Black, non-Hispanic"
label variable phispanic 				"\% Hispanic"
label variable pfemale 					"\% female"
label variable page65_up				"\% aged 65 and up"
label variable punemployed				"\% unemployed"
label variable pbelowpoverty 			"\% below poverty rate"
label variable medhhinc 				"Median HH income (1k USD)"
label variable nreps					"Number of Representatives"
label variable nwholerep 				"Number of whole representatives"
label variable nsharedrep 	 			"Number of shared representatives"
label variable pop 						"Population"
label variable pbachelors				"\% with college degree"

label variable logvap 					"\$ln\$(Voting age pop)"
label variable logpsi_cvap				"\$ln\$(Avg. share of voters)"
label variable logpsi_cvap_delta		"\$ln\$(Decisiveness \$\times\$ Avg. share of voters)"
label variable logRI_cvap 	   			"\$ln\$(Representation Index)"
label variable logRI_turnout			"\$ln\$(Representation Index, Turnout)"
label variable RI_cvap 	   				"Representation Index"
label variable psi_cvap_bar 				"Average share of voters"
label variable RRI						"Relative Representation Index"

label variable logRI_turnout			"\$ln\$(Representation Index, Turnout)"
label variable logRI_edu				"\$ln\$(Representation Index, Education)"
label variable logRI_winning			"\$ln\$(Representation Index, Core voters)"

label variable logRI_cvap_swing			"\$ln\$(Representation Index, Swing voters)"
label variable logRI_cvap_delta			"\$ln\$(Representation Index, Decisiveness)"

label variable pop 						"Population"
label variable pop100k 					"Population (100k)"
label variable logpop					"\$ln\$(Population)"
label variable logcvap					"\$ln\$(CVAP)"
label variable pop2 "Population\$^2\$"
label variable pop3 "Population\$^3\$"

label variable logschoolage "\$ln\$(School age pop.)"
label variable schoolage100k "School-age pop. (100k)"
label variable schoolage2 "School-age pop.\$^2\$"
label variable schoolage3 "School-age pop.\$^3\$"

label variable cvap100k "CVAP (100k)"
label variable cvap2 "CVAP\$^2\$"
label variable cvap3 "CVAP\$^3\$"

label variable lognreps					"\$ln\$(Number of representatives)"
label variable TSV_cvap 				"Total share of voters, CVAP"
label variable TSV_turnout				"Total share of voters, Turnout"
label variable turnout 		 			"Turnout"
label variable pturnout 		 		"Turnout rate"
label variable uncontested  			"Number of uncontested districts"
label variable pdemreps 				"\% Dem. representatives"
label variable pincumbent 				"\% incumbent representatives"
label variable demmajority				"Dem. majority in house"
label variable pdemrepsxdemmajority 	"\% Dem. reps \$\times\$ Dem. control"
label variable dvotesd 					"Swingness (dev. Dem. vote share)"
label variable puncontested				"\% uncontested elections"
label variable rev_state_1m				"Transfers, state to local (1m USD)"
label variable rev_statepc				"Transfers, state to local (p.c.)"

label variable drawnby_leg_gov "Political map"


label variable exp_tot_1m "Expenditures (1M USD)"
label variable rev_tot_1m "Revenue (1M USD)"
label variable rev_state_1m "Transfers from State to Local (1M USD)"
label variable prev_fromstate "Transfers from state (\% Rev.)"

label variable rev_stateeducation_share "Education" 
label variable rev_statepublicwelf_share "Welfare"
label variable rev_statehighways_share "Highway" 
label variable rev_statehealthhos_share "Health and Hospitals"
label variable rev_stateother_share  "Other"



cd "$TablesPath/"


********************************************************************************
*
*	Tables 1, B3, and B5. Main OLS estimates
*
********************************************************************************

reghdfe logrev_state logRI_cvap logpop logcvap ,  a(stateyear) vce(cluster $cvar)
eststo A
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : A
	estadd local syfe "X" : A
	estadd local cfe "" : A

reghdfe logrev_state logRI_cvap logpop logcvap   $x  $pol ,  a(stateyear) vce(cluster $cvar)
eststo A_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : A_X
	estadd local syfe "X" : A_X
	estadd local cfe "" : A_X

reghdfe logrev_state logRI_cvap logpop logcvap ,  a(countyid stateyear) vce(cluster $cvar)
eststo A_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "" : A_FE
	estadd local syfe "X" : A_FE
	estadd local cfe "X" : A_FE
	
reghdfe logrev_state logRI_cvap logpop logcvap	$x  $pol ,  a(countyid stateyear) vce(cluster $cvar)
eststo A_FE_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : A_FE_X
	estadd local syfe "X" : A_FE_X
	estadd local cfe "X" : A_FE_X
	
reghdfe logrev_state lognreps logpsi_cvap logpop logcvap ,  a(stateyear) vce(cluster $cvar) 
eststo B
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	test lognreps=logpsi_cvap 
	estadd scalar pF=r(p): B

	estadd local contr "X" : B
	estadd local syfe "X" : B
	estadd local cfe "" : B
	
reghdfe logrev_state lognreps logpsi_cvap logpop logcvap $x $pol , a(stateyear) vce(cluster $cvar) 
eststo B_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	test lognreps=logpsi_cvap 
	estadd scalar pF=r(p): B_X

	estadd local contr "X" : B_X
	estadd local syfe "X" : B_X
	estadd local cfe "" : B_X
	
reghdfe logrev_state lognreps logpsi_cvap logpop logcvap, a(countyid stateyear) vce(cluster $cvar) 
eststo B_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	test lognreps=logpsi_cvap 
	estadd scalar pF=r(p): B_FE
	
	estadd local contr "" : B_FE
	estadd local syfe "X" : B_FE
	estadd local cfe "X" : B_FE
	
reghdfe logrev_state lognreps logpsi_cvap logpop logcvap  $x $pol	  , a(countyid stateyear) vce(cluster $cvar) 
eststo B_FE_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	test lognreps=logpsi_cvap 
	estadd scalar pF=r(p): B_FE_X
	
	estadd local contr "X" : B_FE_X
	estadd local syfe "X" : B_FE_X
	estadd local cfe "X" : B_FE_X

/// TABLE 1. Main estimates
estout A_FE A_FE_X B_FE B_FE_X using logpsiols.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(cfe syfe contr N ymean r2_a pF, fmt(0 0 0 0 2 3 3) labels("County FE" "State-year FE"  "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" "\$p\$-value for  \$H_0:\pi_1=\pi_2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute("\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap lognreps logpsi_cvap  logpop logcvap) ///
	order(logRI_cvap lognreps logpsi_cvap  logpop logcvap) 
	
// TABLE B3. State-year fixed effects only
estout A A_X B B_X using logpsiols_styrfe.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe contr N ymean r2_a pF, fmt(0 0 0 2 3 3) labels("State-year FE" "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" "\$p\$-value for  \$H_0:\pi_1=\pi_2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute("\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap lognreps logpsi_cvap  logpop logcvap) ///
	order(logRI_cvap lognreps logpsi_cvap  logpop logcvap) 

// TABLE B5. Report all coefficients
estout A_X  A_FE_X B_X  B_FE_X using logpsiols_all.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe N ymean, fmt(0 0 0 2 ) labels("State-year FE" "County FE" "N" "Dependent variable mean"  )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(\quad "" "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	drop(_cons) ///
	order(logRI_cvap lognreps logpsi_cvap  logpop logcvap) 

	
// In-text sumstats to interpret Table 1

* median income per capita
sum rev_statepc , detail

* standard deviation in RI_vap
sum logRI_cvap 


// In-text sumstats to describe median number of governments 


sum ngov*

	

********************************************************************************
*
*	Fig 2: Total share of voters vs. Number of representatives
*
********************************************************************************
	
//set seed 16234

set seed 142022
gen jitter = runiform(-.35,.35)

gen scatter_x=nreps-jitter
gen scatter_x2=nreps+jitter 

gen med_x=nreps


egen med=median(TSV_cvap) ,by(nreps)
egen p25=pctile(TSV_cvap) , p(25) by(nreps)
egen p75=pctile(TSV_cvap), p(75) by(nreps)
egen p5=pctile(TSV_cvap) ,p(5) by(nreps)
egen p95=pctile(TSV_cvap) ,p(95) by(nreps)


gen uav=p75+1.5*(p75-p25)
gen lav=p25-1.5*(p75-p25)


graph twoway ///  
(scatter TSV_cvap scatter_x if  nreps<8 ,  mcolor(ltblue) msymbol(circle_hollow) msize(vsmall) ///
		graphregion(color(white) lcolor(white) lwidth(vvvthick) lstyle(none)) plotregion(lstyle(none) lcolor(white) )  ///
		ytitle("Total Share of Voters", size(vlarge)) xtitle("Number of Representatives", size(vlarge)) ///
		ylabel(,  nogrid) xlabel(1(1)7, nogrid) legend(off) ) ///
(rcap p75 med nreps if nreps<8, lcolor(dknavy) lwidth(medthick) ) ///
(rcap med p25 nreps if nreps<8, lcolor(dknavy) lwidth(medthick)  ) 

graph export nrepsscatter_box.pdf, replace


/// Summary statistics for types of counties described on p. 19 

gen county_is_district=nsharedrep==0 & nreps==1 
gen county_is_mdistrict=nsharedrep==0 & nreps>1
gen county_is_nested = ndistricts==1 & nsharedrep>0 
gen county_is_mismatch = ndistricts>1 & nsharedrep>0

sum county_is* 



********************************************************************************
*
*	Section 7. Implications for gerrymandering
*
********************************************************************************

egen sd_RI_cvap_state=sd(RI_cvap), by(stateyear)
pwcorr sd_RI_cvap_state drawnby_leg_gov, sig



********************************************************************************
*
*	ONLINE APPENDIX TABLE A.1: Decisiveness
*
********************************************************************************

reghdfe logrev_state logRI_cvap_delta logpop logcvap   , a(countyid stateyear) vce(cluster stateyear) keepsin
eststo A_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "" : A_FE
	estadd local syfe "X" : A_FE
	estadd local cfe "X" : A_FE

reghdfe logrev_state logRI_cvap_delta logpop logcvap $x  $pol  , a(countyid stateyear) vce(cluster stateyear) keepsin
eststo A_FE_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : A_FE_X
	estadd local syfe "X" : A_FE_X
	estadd local cfe "X" : A_FE_X

reghdfe logrev_state logpsi_cvap_delta lognreps logpop logcvap	  , a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo B_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	test lognreps=logpsi_cvap_delta 
	estadd scalar pF=r(p): B_FE
	
	estadd local contr "" : B_FE
	estadd local syfe "X" : B_FE
	estadd local cfe "X" : B_FE

reghdfe logrev_state logpsi_cvap_delta lognreps logpop logcvap  $x $pol	   , a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo B_FE_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	test lognreps=logpsi_cvap_delta 
	estadd scalar pF=r(p): B_FE_X
	
	estadd local contr "X" : B_FE_X
	estadd local syfe "X" : B_FE_X
	estadd local cfe "X" : B_FE_X

estout A_FE A_FE_X B_FE B_FE_X using logpsiolsdelta.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(cfe syfe contr N ymean r2_a pF, fmt(0 0 0 0 2 3 3) labels("County FE" "State-year FE"  "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" "\$p\$-value for  \$H_0:\pi_1=\pi_2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute("\_cons " \_cons) ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap_delta logpsi_cvap_delta lognreps logpop logcvap) ///
	order(logRI_cvap_delta logpsi_cvap_delta lognreps logpop logcvap)

	
********************************************************************************
*
*	TABLE B1. Summary Statistics
*
********************************************************************************

mata: mata clear

gen heading1=""
gen heading2=""
gen heading3=""
gen heading4=""
label var heading1 "\textit{Transfers from State}"
label var heading2 "\textit{Representation}"
label var heading3 "\textit{Political Covariates}"
label var heading4 "\textit{Other Covariates}"

local sumvars1  rev_state_1m rev_statepc  
local sumvars2  nreps RI_cvap psi_cvap_bar
local sumvars3  pincumbent puncontested pdemreps demmajority 
local sumvars4 pop100k pcvap purban pbelowpoverty medhhinc pblacknh phispanic pfemale pbachelors page65_up punemployed

foreach k of numlist 1/4 { //number of groups of variables

//compute summary statistics
local count: word count heading`k' `sumvars`k''
mat sumstat = J(`count',2,.)
mat pctile = J(`count',5,.)

local i = 1


foreach var in heading`k' {

	qui: sum `var' , d
    mat sumstat[`i',1] = r(mean)
    mat sumstat[`i',2] = r(sd)
	
	mat pctile[`i',1] = r(p1)
    mat pctile[`i',2] = r(p25)
	mat pctile[`i',3] = r(p50)
    mat pctile[`i',4] = r(p75)	
	mat pctile[`i',5] = r(p99)
	
	local ++ i 
	
foreach var in `sumvars`k'' {
	
	// indent label in Tex table
	local old_label : variable label `var'
	label variable `var' "\quad `old_label'"

    qui: sum `var' , d
    mat sumstat[`i',1] = r(mean)
    mat sumstat[`i',2] = r(sd)
		
	mat pctile[`i',1] = r(p1)
    mat pctile[`i',2] = r(p25)
	mat pctile[`i',3] = r(p50)
    mat pctile[`i',4] = r(p75)	
	mat pctile[`i',5] = r(p99)
	
	local ++ i 
}
}

//convert matrix to table
matrix rownames sumstat= heading`k' `sumvars`k''
frmttable, statmat(sumstat) store(sumstat`k') sfmt(f,f)  varlabels
frmttable, statmat(pctile)  store(pctile`k')  sfmt(f, f, f, f, f) varlabels
}


count  
local N `r(N)'

// merge and append tables
outreg ,  ///
	replay(sumstat1) append(sumstat2) store(sumstat12) ///
	tex nocenter note("") fragment plain /// 
	ctitles( "" "Mean" "SD" ) 	

outreg ,  ///
	replay(sumstat12) append(sumstat3) store(sumstat13) ///
	tex nocenter note("") fragment plain /// 
	ctitles( "" "Mean" "SD" ) 	
	
outreg ,  ///
	replay(sumstat13) append(sumstat4) store(sumstat14) ///
	tex nocenter note("") fragment plain /// 
	ctitles( "" "Mean" "SD" ) 	
	
	
outreg , ///
	replay(pctile1) append(pctile2) store(pctile12) ///
	tex nocenter note("") fragment plain /// 
	ctitles("p1" "p25" "p50" "p75" "p99")  
	
outreg , ///
	replay(pctile12) append(pctile3) store(pctile13) ///
	tex nocenter note("") fragment plain   
	
outreg , ///
	replay(pctile13) append(pctile4) store(pctile14) ///
	tex nocenter note("") fragment plain   
	
	
outreg using sumstats.tex, replace ///
	replay(sumstat14) merge(pctile14) ///
	tex nocenter note("") fragment plain   ///
	addrows("Number of Observations" , "`N'") hlines(01{0}10)

drop heading* 


/// In-text summary statistics (aggregate to state-year level)

egen transfer=total(rev_state), by(state year)
egen exp=total(exp_tot), by(state year)
egen rev=total(rev_tot), by(state year)
sum transfer exp rev if year==2017 // use most recent year in intro

sum transfer exp rev 


********************************************************************************
*
*	TABLE B2. Panel B. Summary Statistics, state transfer details
*
********************************************************************************

mata: mata clear

gen heading1=""
gen heading2=""

label var heading1 "\textit{Total Revenue and Expenditure}"
label var heading2 "\textit{Percent of Transfers, by Purpose}"

local sumvars1  exp_tot_1m rev_tot_1m rev_state_1m prev_fromstate
local sumvars2  rev_stateeducation_share rev_statepublicwelf_share rev_statehighways_share rev_statehealthhos_share rev_stateother_share

foreach k of numlist 1/2 { //number of groups of variables

//compute summary statistics
local count: word count heading`k' `sumvars`k''
mat sumstat = J(`count',2,.)
mat pctile = J(`count',5,.)

local i = 1


foreach var in heading`k' {

	qui: sum `var' , d
	mat sumstat[`i',1] = r(mean)
    mat sumstat[`i',2] = r(sd)
	
	mat pctile[`i',1] = r(min)
    mat pctile[`i',2] = r(p25)
	mat pctile[`i',3] = r(p50)
    mat pctile[`i',4] = r(p75)	
	mat pctile[`i',5] = r(max)
	
	local ++ i 
	
foreach var in `sumvars`k'' {
	
	// indent label in Tex table
	local old_label : variable label `var'
	label variable `var' "\quad `old_label'"

    qui: sum `var' , d
	mat sumstat[`i',1] = r(mean)
    mat sumstat[`i',2] = r(sd)
	
	mat pctile[`i',1] = r(p1)
    mat pctile[`i',2] = r(p25)
	mat pctile[`i',3] = r(p50)
    mat pctile[`i',4] = r(p75)	
	mat pctile[`i',5] = r(p99)
	
	local ++ i 
}
}

//convert matrix to table
matrix rownames sumstat= heading`k' `sumvars`k''
frmttable, statmat(sumstat) store(sumstat`k') sfmt(f,f)   varlabels
frmttable, statmat(pctile)  store(pctile`k')  sfmt(f, f, f, f, f) varlabels
}


count 
local N `r(N)'


//merge and append  tables


outreg ,  ///
	replay(sumstat1) append(sumstat2) store(sumstat12) ///
	tex nocenter note("") fragment plain /// 
	ctitles( "" "Mean" "SD" ) 	
	
outreg , ///
	replay(pctile1) append(pctile2) store(pctile12) ///
	tex nocenter note("") fragment plain /// 
	ctitles("p1" "p25" "p50" "p75" "p99")  
	
outreg using sumstats_localexp.tex, replace ///
	replay(sumstat12) merge(pctile12) ///
	tex nocenter note("") fragment plain   ///
	addrows("Number of Observations" , "`N'") hlines(01{0}10)

drop heading* 


********************************************************************************
*
*	Table B4. Correlates of RI_vap
* 
********************************************************************************

reghdfe RI_cvap logpop logcvap	 $x  $pol ,  a(stateyear) vce(cluster $cvar)
eststo A
	sum logRI_cvap if e(sample)==1
	estadd scalar ymean=r(mean)		
	
	estadd local syfe "X" : A
	estadd local cfe "" : A
	
reghdfe  RI_cvap logpop logcvap	 $x  $pol ,  a(countyid stateyear) vce(cluster $cvar)
eststo B
	sum logRI_cvap if e(sample)==1
	estadd scalar ymean=r(mean)		
	
	estadd local syfe "X" : B
	estadd local cfe "X" : B

estout A B   using balance.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe N ymean r2_a  , fmt(0 0 0 2 3 ) labels( "State-year FE" "County FE" "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(\quad \ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logpop logcvap $x $pol ) ///
	order(logpop logcvap $x $pol)



	
********************************************************************************
*
*	Table B6. Flexible population controls
*
********************************************************************************

label variable pop100k "Population (100k)"
global xnovap purban pbelowpoverty medhhinc pblack phispanic pfemale punemployed pbachelors page65_up
		  
reghdfe logrev_state  logRI_cvap logpop   $xnovap $pol	  , a(countyid stateyear) vce(cluster $cvar )
eststo A0
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : A0
	estadd local syfe "" : A0
	estadd local cfe "X" : A0
	estadd local yfe "X" : A0
	
reghdfe logrev_state  logRI_cvap logpop logschoolage  $xnovap $pol	  , a(countyid stateyear) vce(cluster $cvar )
eststo A_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : A_FE
	estadd local syfe "" : A_FE
	estadd local cfe "X" : A_FE
	estadd local yfe "X" : A_FE
	
reghdfe logrev_state logRI_cvap  pop100k pop2 pop3 schoolage100k schoolage2 schoolage3   $xnovap $pol	  , a(countyid stateyear) vce(cluster $cvar )
eststo B_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)		
	estadd local contr "X" : B_FE
	estadd local syfe "" : B_FE
	estadd local cfe "X" : B_FE
	estadd local yfe "X" : B_FE
	
	
reghdfe logrev_state logRI_cvap  pop100k pop2 pop3 cvap100k cvap2 cvap3  $xnovap  $pol  , a(countyid stateyear) vce(cluster $cvar )
eststo C_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : C_FE
	estadd local syfe "" : C_FE
	estadd local cfe "X" : C_FE
	estadd local yfe "X" : C_FE	

estout A0 A_FE B_FE C_FE  using robust_pop.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(cfe yfe contr N ymean r2_a, fmt(0 0 0 0 2 3 3) labels("County FE" "State-Year FE" "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$"  )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap logpop logschoolage pop100k pop2 pop3 schoolage100k schoolage2 schoolage3  cvap100k cvap2 cvap3) ///
	order(logRI_cvap logpop logschoolage pop100k pop2 pop3 schoolage100k schoolage2 schoolage3  cvap100k cvap2 cvap3) 
	

	
********************************************************************************
*
* Table B7. Naive estimates: county-level measures only, excluding relative measures 
*
********************************************************************************


reghdfe logrev_state lognreps  logpop logcvap , a(stateyear) vce(cluster $cvar)
eststo A
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)		
	
	estadd local contr "" : A
	estadd local syfe "X" : A
	estadd local cfe "" : A


reghdfe logrev_state lognreps  logpop logcvap 	  $x $pol , a(stateyear) vce(cluster $cvar)
eststo A_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)		
	
	estadd local contr "X" : A_X
	estadd local syfe "X" : A_X
	estadd local cfe "" : A_X
	
reghdfe logrev_state lognreps  logpop logcvap , a(countyid stateyear) vce(cluster $cvar)
eststo B
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)		
	
	estadd local contr "" : B
	estadd local syfe "X" : B
	estadd local cfe "X" : B

	
reghdfe logrev_state lognreps  logpop logcvap 	  $x $pol , a(countyid stateyear) vce(cluster $cvar)
eststo B_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)		
	
	estadd local contr "X" : B_X
	estadd local syfe "X" : B_X
	estadd local cfe "X" : B_X
	

estout A A_X B B_X  using testneighbors.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe contr N ymean r2_a  , fmt(0 0 0 0 2 3 ) labels( "State-year FE" "County FE" "Additional controls" "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(lognreps logpop logcvap  ) ///
	order(lognreps logpop logcvap )
	
********************************************************************************
*
*	FIGURE 5 and TABLE B8. Other Outcomes: Federal transfers, local transfers, local revenue
*
********************************************************************************

// Drop counties that receive no transfers as well as HI and AK, where a significant number of areas have no local education agencies
gen subsample= state_a!="HI" & state_a!="AK" & rev_statenotedu!=0 & rev_stateeducation!=0 & rev_fedloc!=0 & exp_edu!=0 

egen balanced_subsample = total(inrange(year, 2002, 2017)) if subsample==1, by(countyid)
replace subsample=0 if balanced_subsample!=3 

local otheroutcomes logrev_state logrev_stateeducation logrev_statenotedu logrev_fedloc logrev_tot logrev_own logexp_tot logexp_edu logexp_notedu

local i 1
foreach y in `otheroutcomes' {
	
	reghdfe `y' logRI_cvap  logpop logcvap  $x  $pol if subsample==1 , a(countyid stateyear) vce(cluster $cvar) 
	
	eststo A`i'
	
	sum `y' if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : A`i'
	estadd local syfe "X" : A`i'
	estadd local cfe "X" : A`i'
	
	local ++i
}
    
estout  A1 A2 A3 A4  using otheroutcomes.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe contr N ymean r2_a  , fmt(0 0 0 0 2 3 ) labels( "State-year FE" "County FE" "Additional controls" "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	mgroups("\specialcell{State\\transfers\\ }" "\specialcell{State\\transfers,\\ edu.}" "\specialcell{ State\\transfers,\\ not edu.}" "\specialcell{Other \\ transfers}"  , pattern(1 1 1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap  logpop logcvap) ///
	substitute(logRI_cvap  logpop logcvap)

estout A5 A6 A7 A8 A9 using otheroutcomes.tex, append ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe contr N ymean r2_a  , fmt(0 0 0 0 2 3 ) labels( "State-year FE" "County FE" "Additional controls" "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels((5) (6) (7) (8) (9)) nonum ///
	mgroups("\specialcell{\\ Revenue}" "\specialcell{\\Revenue \\ less state \\transfers}"   "\specialcell{\\ Exp.}" "\specialcell{\\ Exp., \\edu.}" "\specialcell{\\ Exp., \\not edu.}" , pattern(1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap  logpop logcvap) ///
	substitute(logRI_cvap  logpop logcvap)	
	
	
/// FIGURE 5. Coefplot 

        matrix C = J(3,9,.)
        matrix rownames C = beta ll95 ul95 
       
		local i 1
        foreach y in `otheroutcomes' {
           
		   est replay A`i'
		   matlist r(table)
		   matrix C[1,`i'] = r(table)[1,1] \ r(table)[5,1] \ r(table)[6,1] 
		   local N`i' `e(N)'
			
			local ++i
		}
       
	   
//coefplot matrix(C), ci((2 3)) vert yline(0) coeflabels(,wrap(10) labsize(small))  ///
coefplot matrix(C), ci((2 3))  xline(0, lcolor(gray) lpattern(dash)) ///
		graphregion(color(white) lcolor(white) lwidth(5cm) lstyle(none)) plotregion(lstyle(none) lcolor(white) ) ///
		fcolor(none) lcolor(black) ///
		graphregion(color(white) lcolor(white) lwidth(vvvthick) lstyle(none)) plotregion(lstyle(none) lcolor(white) ) /// 
		ylabel(, nogrid) xlabel(, nogrid)  xsize(7) ///
		coeflabels(c1="Transfers from state, total" 	///
				   c2="Transfers from state, education" 	///
				   c3="Transfers from state, not education" 	///
				   c4="Transfers from other governments" 	/// 
				   c5="County revenue, total" 	/// 
				   c6="County revenue, less state transfers" 	/// 
				   c7="County expenditures, total" 	/// 	
				   c8="County expenditures, education" 	/// 
				   c9="County expenditures, not education" 	/// 
				   ,labsize(vlarge))  ///
	     xtitle("Coefficient for {it:ln}(Representation Index)", size(vlarge)) ///
		 headings(logrev_state = "{bf:Intergovernmental Transfers:}"                ///
					logrev_tot = "{bf:Revenue:}" ///
					logexp_tot = "{bf:Expenditure:}" ///
					, nogap)  
					
graph export coefplot_otheroutcomes.pdf, replace


// summary statistics to interpret results

foreach i in rev_tot exp_tot rev_state {	
	qui sum `i' if subsample==1
	local m_`i'=`r(mean)'
}

* full pass-through of 10\% increase in transfers, as % of revenue
di `m_rev_state'*.10 / `m_rev_tot'

* full pass-through of 10\% increase in transfers, as % of expenditures
di `m_rev_state'*.10 / `m_exp_tot'


	
********************************************************************************
*
*	Table B9: Other mechanisms: Lobbying
*
********************************************************************************

label variable lobby "Hired state lobbyist" 

reghdfe  lobby logRI_cvap logpop logcvap, a(stateyear) vce(cluster $cvar)
eststo A 

	sum lobby if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "" : A
	estadd local syfe "X" : A
	estadd local cfe "" : A
	estadd local yfe "" : A
	
reghdfe  lobby logRI_cvap logpop logcvap $x $pol , a(stateyear) vce(cluster $cvar)
eststo B 

	sum lobby if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : B
	estadd local syfe "X" : B
	estadd local cfe "" : B
	estadd local yfe "" : B
	
reghdfe lobby logRI_cvap logpop logcvap  , a(countyid stateyear) vce(cluster $cvar)
eststo C

	sum lobby if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "" : C
	estadd local syfe "X" : C
	estadd local cfe "X" : C
	estadd local yfe "" : C
	
reghdfe lobby logRI_cvap logpop logcvap   $x  $pol    , a(countyid stateyear) vce(cluster $cvar)
eststo D

	sum lobby if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : D
	estadd local syfe "X" : D
	estadd local cfe "X" : D
	estadd local yfe "" : D
	

estout A B C D  using lobbying.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe contr cfe N ymean r2_a , fmt(0 0 0 0 2 %9.3f ) labels("State-year FE" "Additional controls" "County FE"  "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap logpop logcvap ) ///
	order(logRI_cvap logpop logcvap ) 
	

********************************************************************************
*
*	Table B10: Other mechanisms: fragmentation
*
********************************************************************************

label variable fragmentation "Fragmentation" 

reghdfe logrev_state logRI_cvap logpop logcvap  fragmentation   , a(countyid stateyear) vce(cluster $cvar)
eststo A

	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "" : A
	estadd local syfe "X" : A
	estadd local cfe "X" : A

	
reghdfe logrev_state logRI_cvap logpop logcvap fragmentation  $x $pol  , a(countyid stateyear) vce(cluster $cvar)
eststo B
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : B
	estadd local syfe "X" : B
	estadd local cfe "X" : B

estout A B  using fragmentation.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe  contr N ymean r2_a , fmt(0 0 0 0 2 3 ) labels("State-year FE" "County FE" "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap fragmentation  logpop logcvap ) ///
	order(logRI_cvap fragmentation  logpop logcvap ) 


	
	
********************************************************************************
*
*	Table B12 . Sub-sample anlaysis by who drew the court 
*
********************************************************************************
	
*use keepsin otherwise a substantial number of observations are dropped due to changes in who drew map	
	
reghdfe logrev_state logRI_cvap  logpop logcvap 	   if drawnby_leg_gov==0,  a(countyid stateyear) vce(cluster $cvar) keepsin 
eststo A
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : A
	estadd local syfe "X" : A
	estadd local cfe "X" : A
	estadd local yfe "" : A
	
reghdfe logrev_state logRI_cvap  logpop logcvap 	 $x  $pol  if drawnby_leg_gov==0, a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo A_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : A_X
	estadd local syfe "X" : A_X
	estadd local cfe "X" : A_X
	estadd local yfe "X" : A_X

	
reghdfe logrev_state logRI_cvap  logpop logcvap 	  if drawnby_leg_gov==1,  a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo B
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : B
	estadd local syfe "X" : B
	estadd local cfe "X" : B
	estadd local yfe "" : B
	
reghdfe logrev_state logRI_cvap  logpop logcvap 	 $x  $pol   if drawnby_leg_gov==1, a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo B_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : B_X
	estadd local syfe "X" : B_X
	estadd local cfe "X" : B_X
	estadd local yfe "X" : B_X	

estout A A_X B B_X using subsample_draw.tex, replace ///
cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe contr N ymean r2_a , fmt(0 0 0 0 2 3 ) labels("State-year FE" "County FE" "Additional controls"   "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	mgroups( "\specialcell{Map drawn by \\ Commission \\or Court}"  "\specialcell{Map drawn by \\ Legislature or \\Governor}" , pattern(1 0 1 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap  logpop logcvap) ///
	order(logRI_cvap logpop logcvap) 
	

********************************************************************************
*
*	Table B13. Sub-sample anlaysis by competitive vs. uncompetitive districts
*
********************************************************************************


reghdfe logrev_state logRI_cvap  logpop logcvap  if  anyclose_30!=.,  a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo A
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : A
	estadd local syfe "X" : A
	estadd local cfe "X" : A
	
reghdfe logrev_state logRI_cvap  logpop logcvap  $x  $pol   if  anyclose_30!=., a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo B
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : B
	estadd local syfe "X" : B
	estadd local cfe "X" : B
	
reghdfe logrev_state logRI_cvap  logpop logcvap   if  anyclose_30==0,  a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo C
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : C
	estadd local syfe "X" : C
	estadd local cfe "X" : C
	
reghdfe logrev_state logRI_cvap  logpop logcvap  $x  $pol   if  anyclose_30==0, a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo D
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : D
	estadd local syfe "X" : D
	estadd local cfe "X" : D

reghdfe logrev_state logRI_cvap  logpop logcvap  if  anyclose_30==1,  a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo E
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : E
	estadd local syfe "X" : E
	estadd local cfe "X" : E
	
reghdfe logrev_state logRI_cvap  logpop logcvap  $x  $pol   if anyclose_30==1, a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo F
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : F
	estadd local syfe "X" : F
	estadd local cfe "X" : F
	estadd local yfe "X" : F	
	
estout A B C D E F using subsample_close.tex, replace ///
cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe contr N ymean r2_a , fmt(0 0 0 0 2 3 ) labels("State-year FE" "County FE" "Additional controls"   "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	mgroups( "\specialcell{All  counties \\with election \\ data}" "\specialcell{No competitive \\ elections}" "\specialcell{At least one \\ competitive  \\election}"  "\specialcell{In District(s) with \\Close Elections}" , pattern(1 0 1 0 1 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap  logpop logcvap) ///
	order(logRI_cvap logpop logcvap) 
	


********************************************************************************
*
*	Table B14. Education spending by single vs. many school districts
*
********************************************************************************
	
reghdfe logrev_state logRI_cvap	logpop	logcvap  if nschool_med1==1 , a(countyid stateyear) vce(cluster $cvar) keepsin
eststo A
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : A
	estadd local syfe "X" : A
	estadd local cfe "X" : A
	
reghdfe logrev_state logRI_cvap	logpop	logcvap $x $pol  if nschool_med1==1 , a(countyid stateyear) vce(cluster $cvar) keepsin
eststo A_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : A_X
	estadd local syfe "X" : A_X
	estadd local cfe "X" : A_X

reghdfe logrev_state logRI_cvap	logpop	logcvap  	 if nschool_med1==0 , a(countyid stateyear) vce(cluster $cvar) keepsin
eststo B
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	


	estadd local contr "" : B
	estadd local syfe "X" : B
	estadd local cfe "X" : B
	
reghdfe logrev_state logRI_cvap	logpop	logcvap  $x $pol	 if nschool_med1==0 , a(countyid stateyear) vce(cluster $cvar) keepsin
eststo B_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	


	estadd local contr "X" : B_X
	estadd local syfe "X" : B_X
	estadd local cfe "X" : B_X
	
reghdfe logrev_state logRI_cvap	logpop	logcvap  if state_county_school==1 , a(countyid stateyear) vce(cluster $cvar) keepsin
eststo C
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : C
	estadd local syfe "X" : C
	estadd local cfe "X" : C
	
	
reghdfe logrev_state logRI_cvap	logpop	logcvap $x $pol if state_county_school==1 , a(countyid stateyear) vce(cluster $cvar) keepsin
eststo C_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : C_X
	estadd local syfe "X" : C_X
	estadd local cfe "X" : C_X

reghdfe logrev_state logRI_cvap	logpop	logcvap  	 if state_county_school==0 , a(countyid stateyear) vce(cluster $cvar) keepsin
eststo D
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "" : D
	estadd local syfe "X" : D
	estadd local cfe "X" : D
	

reghdfe logrev_state logRI_cvap	logpop	logcvap  $x $pol	 if state_county_school==0 , a(countyid stateyear) vce(cluster $cvar) keepsin
eststo D_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : D_X
	estadd local syfe "X" : D_X
	estadd local cfe "X" : D_X


estout A A_X B B_X using logpsiols_edu.tex, replace ///
cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe  contr N ymean r2_a , fmt(0 0 0 0 2 3 ) labels("State-year FE" "County FE" "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	mgroups("\specialcell{Median school \\districts per \\county \\=1}" "\specialcell{Median school \\districts per \\county \\\$>1\$ }", pattern(1 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap  logpop logcvap) ///
	order(logRI_cvap logpop logcvap) 
	
estout C C_X D D_X using logpsiols_edu.tex, append ///
cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe  contr N ymean r2_a , fmt(0 0 0 0 2 3 ) labels("State-year FE" "County FE" "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels((5) (6) (7) (8))  nonum ///
	mgroups("\specialcell{\\ Number of county school \\districts \$>0\$}" "\specialcell{\\ Number of county school \\districts \$=0\$}", pattern(1 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap  logpop logcvap) ///
	order(logRI_cvap logpop logcvap) 
	

	
********************************************************************************
*
*	TABLE B15. Alternative measures of Representation Index
*
********************************************************************************
	
gen temp_sample=.

reghdfe logrev_state  logRI_turnout  logpop logcvap		 $x  $pol ,  a(stateyear countyid) vce(cluster $cvar) keepsin
eststo A
	
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : A
	estadd local syfe "X" : A
	estadd local cfe "X" : A
	
replace temp_sample=e(sample)==1

reghdfe logrev_state logRI_cvap logRI_turnout  logpop logcvap		 $x  $pol if temp_sample==1 ,  a(stateyear countyid) vce(cluster $cvar) keepsin
eststo B
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : B
	estadd local syfe "X" : B
	estadd local cfe "X" : B

replace temp_sample=.

reghdfe logrev_state  logRI_edu  logpop logcvap		 $x  $pol  ,  a(stateyear countyid) vce(cluster $cvar) keepsin
eststo C

	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : C
	estadd local syfe "X" : C
	estadd local cfe "X" : C

replace temp_sample=e(sample)==1


reghdfe logrev_state logRI_cvap logRI_edu  logpop logcvap		 $x  $pol if temp_sample==1 ,  a(stateyear countyid) vce(cluster $cvar) keepsin
eststo D

	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : D
	estadd local syfe "X" : D
	estadd local cfe "X" : D

replace temp_sample=. 

reghdfe logrev_state   logRI_winning 	logpop logcvap $x  $pol ,  a(stateyear countyid) vce(cluster $cvar) keepsin
eststo E
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : E
	estadd local syfe "X" : E
	estadd local cfe "X" : E
	
replace temp_sample=e(sample)==1

reghdfe logrev_state logRI_cvap  logRI_winning 	logpop logcvap $x  $pol if temp_sample==1,  a(stateyear countyid) vce(cluster $cvar) keepsin
eststo F
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : F
	estadd local syfe "X" : F
	estadd local cfe "X" : F
	
replace temp_sample=. 

reghdfe logrev_state   logRI_cvap_swing	logpop logcvap $x  $pol ,  a(stateyear countyid) vce(cluster $cvar) keepsin
eststo G
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : G
	estadd local syfe "X" : G
	estadd local cfe "X" : G
	
replace temp_sample=e(sample)==1

reghdfe logrev_state logRI_cvap  logRI_cvap_swing 	logpop logcvap $x  $pol if temp_sample==1,  a(stateyear countyid) vce(cluster $cvar) keepsin
eststo H
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	

	estadd local contr "X" : H
	estadd local syfe "X" : H
	estadd local cfe "X" : H
	

estout A B C D   using other_RI_vap.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe contr N ymean r2_a , fmt(0 0 0 0 2 3 ) labels("State-year FE" "County FE" "Year FE" "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep( logRI_turnout logRI_edu  logRI_cvap) ///
	order(logRI_turnout logRI_edu  logRI_cvap ) 


estout E F G H  using other_RI_vap.tex, append ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(syfe cfe contr N ymean r2_a , fmt(0 0 0 0 2 3 ) labels("State-year FE" "County FE" "Year FE" "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute(_ \_ "\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep( logRI_winning logRI_cvap_swing logRI_cvap) ///
	order(logRI_winning logRI_cvap_swing logRI_cvap) 

	

********************************************************************************
*
*	TABLE B16. Upper house of the legislature
*
********************************************************************************

label variable logRI_cvap			"\$ln\$(Representation Index, Lower house)"
label variable logRI_cvap_u			"\$ln\$(Representation Index, Upper house)"

label variable lognreps				"\$ln\$(Number of representatives, Lower house)"
label variable lognreps_u			"\$ln\$(Number of representatives, Upper house)"

label variable logpsi_cvap			"\$ln\$(Avg. share of voters, Lower house)"
label variable logpsi_cvap_u		"\$ln\$(Avg. share of voters, Upper house)"


reghdfe logrev_state logRI_cvap logRI_cvap_u logpop logcvap , a(countyid stateyear) vce(cluster stateyear) keepsin
eststo A_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "" : A_FE
	estadd local syfe "X" : A_FE
	estadd local cfe "X" : A_FE

	
reghdfe logrev_state logRI_cvap logRI_cvap_u logpop logcvap	$x  $pol  , a(countyid stateyear) vce(cluster stateyear) keepsin
eststo A_FE_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	
	estadd local contr "X" : A_FE_X
	estadd local syfe "X" : A_FE_X
	estadd local cfe "X" : A_FE_X

	
reghdfe logrev_state lognreps logpsi_cvap lognreps_u logpsi_cvap_u  logpop logcvap	  , a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo B_FE
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	test lognreps=logpsi_cvap 
	estadd scalar pF=r(p): B_FE
	
	estadd local contr "" : B_FE
	estadd local syfe "X" : B_FE
	estadd local cfe "X" : B_FE

reghdfe logrev_state lognreps logpsi_cvap lognreps_u logpsi_cvap_u  logpop logcvap  $x $pol	   , a(countyid stateyear) vce(cluster $cvar)  keepsin
eststo B_FE_X
	sum logrev_state if e(sample)==1
	estadd scalar ymean=r(mean)	
	test lognreps=logpsi_cvap 
	estadd scalar pF=r(p): B_FE_X
	
	estadd local contr "X" : B_FE_X
	estadd local syfe "X" : B_FE_X
	estadd local cfe "X" : B_FE_X


estout A_FE A_FE_X B_FE B_FE_X using logpsiols_u.tex, replace ///
	cells((b(fmt(3)star)) (se(fmt(3)par))) ///
	stats(cfe syfe contr N ymean r2_a pF, fmt(0 0 0 0 2 3 3) labels("County FE" "State-year FE"  "Additional controls"  "N" "Dependent variable mean" "Adjusted \$R^2\$" "\$p\$-value for  \$H_0:\pi_1=\pi_2\$" )) ///
	starlevels(\sym{*} 0.10 \sym{**} 0.05 \sym{***} 0.01, label(" \(p<@\)")) ///
	varwidth(12) ///
	modelwidth(12) /// 
	delimiter(&) ///
	end(\\) ///
	posthead("\midrule") ///
	prefoot("\midrule") ///
	mlabels(none) ///
	label ///
	varlabels(_cons Constant, end("" \addlinespace) nolast) ///
	numbers(\multicolumn{@span}{c}{( )}) ///
	collabels(none) ///
	eqlabels(, begin("\midrule" "") nofirst) ///
	substitute("\_cons " \_cons) ///
	interaction(" $\times$ ") ///
	level(95) ///
	style(esttab) ///
	keep(logRI_cvap logRI_cvap_u lognreps logpsi_cvap lognreps_u logpsi_cvap_u  logpop logcvap) ///
	order(logRI_cvap logRI_cvap_u lognreps logpsi_cvap lognreps_u logpsi_cvap_u logpop logcvap)
	



	
